﻿using ConsoleApplication.WebAPI;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace NS
{
    [HotUpdate]
    [Description("组柜登记单-反写调用保存接口触发采购订单反写插件")]
    public class UpdateFDATE : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            base.OnPreparePropertys(e);
        }

        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            foreach (DynamicObject item in e.DataEntitys)
            {
                string FID = "", FNumber="";
                if (item["ID"] != null && Convert.ToString(item["ID"]) != "")
                {
                    FID = Convert.ToString(item["ID"]);
                }
                string SQL = "/*dialect*/" + string.Format(@"UPDATE T SET 
                    t.F_WLLZ_Date2=t8.F_WLLZ_Date11,
                    t.F_WLLZ_Date1=t8.F_WLLZ_Date111,
                    t.F_WLLZ_Date4=t8.F_WLLZ_Date12,
                    t.F_WLLZ_Date5=t8.F_WLLZ_Date13,
                    t.F_WLLZ_Date3=t8.F_WLLZ_Date14,
                    t.FModifyDate='{1}'
                FROM t_PUR_POOrder T
                LEFT JOIN t_PUR_POOrderEntry T1 ON T.FID=T1.FID
                LEFT JOIN T_PUR_ReceiveEntry_LK T2 ON T1.FID=T2.FSBILLID AND T1.FENTRYID=T2.FSID
                LEFT JOIN T_PUR_ReceiveEntry T3 ON T2.FENTRYID=T3.FENTRYID
                LEFT JOIN QZPV_t_Cust_Entry100001_LK T4 ON T3.FID=T4.FSBILLID AND T3.FENTRYID=T4.FSID
                LEFT JOIN QZPV_t_Cust_Entry100001 T5 ON T4.FENTRYID=T5.FENTRYID
                LEFT JOIN QZPV_t_Cust100001 T8 ON T5.FID=T8.FID
                LEFT JOIN T_BAS_PREBDFIVE_LK T6 ON T5.FID=T6.FSBILLID AND T5.FID=T6.FSID
                LEFT JOIN T_BAS_PREBDFIVE T7 ON T6.FID=T7.FID
                WHERE T7.FID='{0}'", FID, Convert.ToString(DateTime.Now));
                DBUtils.ExecuteDynamicObject(this.Context, SQL);
                string SQL1 = "/*dialect*/" + string.Format(@"UPDATE T SET 
                    t.F_WLLZ_Date2=t4.F_WLLZ_Date11,
                    t.F_WLLZ_Date1=t4.F_WLLZ_Date111,
                    t.F_WLLZ_Date4=t4.F_WLLZ_Date12,
                    t.F_WLLZ_Date5=t4.F_WLLZ_Date13,
                    t.F_WLLZ_Date3=t4.F_WLLZ_Date14,
                    t.FModifyDate='{1}'
                FROM t_PUR_POOrder T
                LEFT JOIN t_PUR_POOrderEntry T1 ON T.FID=T1.FID
                LEFT JOIN QZPV_t_Cust_Entry100001_LK T2 ON T1.FID=T2.FSBILLID AND T1.FENTRYID=T2.FSID
                LEFT JOIN QZPV_t_Cust_Entry100001 T3 ON T2.FENTRYID=T3.FENTRYID
                LEFT JOIN QZPV_t_Cust100001 T4 ON T3.FID=T4.FID
                LEFT JOIN T_BAS_PREBDFIVE_LK T5 ON T3.FID=T5.FSBILLID AND T3.FID=T5.FSID
                LEFT JOIN T_BAS_PREBDFIVE T6 ON T5.FID=T6.FID
                WHERE T6.FID='{0}'
               ", FID, Convert.ToString(DateTime.Now));
                DBUtils.ExecuteDynamicObject(this.Context, SQL1);
            }
        }
    }
}
